package com.leslie.springboottest.service;

import com.leslie.springboottest.data.Person;
import com.leslie.springboottest.enums.PersonResponseEnum;
import com.leslie.springboottest.excption.PersonException;
import com.leslie.springboottest.repository.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PersonService {
    @Autowired
    PersonRepository personRepository;

    public void getAge(Integer age) throws PersonException {
        if (age < 10) {
            throw new PersonException(PersonResponseEnum.PRIMARY_SCHOOL);
        } else if(age >10 && age < 16) {
            throw new PersonException(PersonResponseEnum.MIDDLE_SCHOOL);
        }
    }

    public Person findOne(Integer code){
        return personRepository.findById(code).orElse(null);
    }
}
